<!--
  - Copyright (c) 2018.
  - 北京九思金信科技有限公司对该文件内容保留所有权利。
  - 未经许可，不得私自拷贝、传播、发布、引用该文件内容，违者将被追究法律责任。
  -->
<template>
  <div class="home_task_box">
    <div class="task_title">
      <div class="task_title_return" @click="homeGo">
        <img src="@/assets/img/Back@3x.png" alt />
        <span>首页</span>
      </div>
      <p>任务中心</p>
    </div>
    <div class="scroll" ref="scroll">
      <scroll
        v-if="taskData.length"
        :loadDatas="taskData"
        :pullUpLoad="pullUpLoad"
        :pulldown="pulldown"
        @pullingDown="loadDownData"
        @pullingUp="loadUpData"
        class="task_item_box"
      >
        <div class="task_item">
          <div
            class="mission_info"
            v-for="item in taskData"
            :key="item.id"
            @click="taskItem(item)"
          >
            <div class="mission_info_title">
              <img v-lazy="oftenDataInfoImg(item.busiTypeId)" alt />
              <span>{{ item.busiTypeName }}</span>
              <em>{{ item.acceptTime | dateFormat("yyyy/MM/dd hh:mm:ss") }}</em>
              <p>{{ item.messageContent }}</p>
            </div>
            <div class="mission_info_center">
              <p>查看详情</p>
              <img src="@/assets/img/More2@3x.png" alt />
            </div>
          </div>
        </div>
      </scroll>
    </div>

    <!-- loading 组件 -->
    <div v-if="!taskData.length" class="loading-container">
      <joys-loading></joys-loading>
    </div>
  </div>
</template>

<script>
import Scroll from "@/components/JoysScroll/JoysScroll";
import JoysLoading from "@/components/JoysLoading/JoysLoading";
export default {
  name: "task",
  components: {
    Scroll,
    JoysLoading
  },
  data () {
    return {
      pulldown: true,
      pullUpLoad: true,
      taskData: [],
      pageNum: 1
    };
  },
  methods: {
    taskListData () {
      // var _this = this;

      setTimeout(() => {
        //模拟ajax
        this.taskDataQuery(1);
      }, 100);
    },

    loadDownData () {
      console.log("下拉刷新");
      setTimeout(() => {
        this.taskDataQuery(1);
        this.taskData = [];
      }, 1000);
    },
    loadUpData () {
      console.log("上拉加载");
      setTimeout(() => {
        //模拟ajax
        this.pageNum++;
        this.taskDataQuery(this.pageNum);
        console.log(this.pageNum, "2444");
        // this.num++;
        // let newArr = mapArr(this.resultLists, this.num);
        // this.lists = this.lists.concat(newArr);
        // console.log(this.lists);
      }, 1000);
    },

    // 任务列表请求
    taskDataQuery (pageNum) {
      this.$axios({
        method: "get",
        url: "/joys-rest/joys-bpm/taskMessage/byCondition",
        headers: {
          "AUTH-TOKEN": localStorage.getItem("AUTH-TOKEN")
        },
        params: {
          workStatus: "NOT_WORKING",
          pageIndex: pageNum,
          pageSize: 10
        }
      })
        .then(res => {
          this.taskData = this.taskData.concat(res.data.rows);
          console.log(this.taskData, "ffggg");
        })
        .catch(error => {
          console.log(error);
        });
    },
    oftenDataInfoImg (id) {
      if (!id) {
        return require("@/assets/img/defaultImg.png");
      } else {
        return (
          this.$baseUrl +
          "/joys-rest/joys-file/file/browse/one2one/" +
          id +
          "?AUTH-TOKEN=" +
          localStorage.getItem("AUTH-TOKEN")
        );
      }
    },
    homeGo () {
      this.$router.goBack();
    },
    taskItem (item) {
      console.log(item, '数据')
      this.$router.push({
        path: `/home/${item.busiId}`,
        query:{
          taskItemData:item
        }
      });
    }
  },
  mounted () {
    // this.taskListData();
  },
  created () {
    this.taskListData(1);
  }
};
</script>

<style scoped lang="less">
.home_task_box {
  background: #fbf9fe;
  position: fixed;
  top: 0rem;
  bottom: 0.1rem;
  width: 100%;
  height: 100%;
  z-index: 300;
  overflow: hidden;
  .task_title {
    width: 100%;
    height: 0.44rem;
    text-align: center;
    line-height: 0.44rem;
    background: #ffffff;
    box-shadow: inset 0 -1px 0 0 rgba(207, 207, 207, 0.2);
    .task_title_return {
      margin-top: -0.04rem;
      float: left;
      img {
        // width: 0.15rem;
        height: 0.205rem;
        padding-left: 0.085rem;
      }
      span {
        font-family: Regular;
        font-size: 0.17rem;
        color: #3e3e3e;
        letter-spacing: -0.41px;
        line-height: 0.22rem;
      }
    }
    p {
      font-family: Semibold;
      font-size: 0.17rem;
      color: #3e3e3e;
      letter-spacing: -0.41px;
      text-align: center;
      height: 0.44rem;
      line-height: 0.44rem;
      margin-left: 0.7rem;
      margin-right: 0.7rem;
    }
  }
  .scroll {
    width: 100%;
    .task_item_box {
      height: 100%;
      width: 100;
      overflow: hidden;
      margin-top: 0.44rem;
      .task_item {
        // height: 100%;
        // padding-bottom: 0.44rem;
        overflow: hidden;
        .mission_info {
          background: #ffffff;
          box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 0.09);
          border-radius: 0.04rem;
          margin: 0 0.16rem 0.1rem 0.16rem;
          // margin-bottom: 0.1rem;
          padding-bottom: 0.15rem;
          .mission_info_title {
            padding-left: 0.08rem;
            padding-right: 0.16rem;
            margin: 0 0.08rem;
            border-bottom: 1px #eeeeee solid;
            padding-top: 0.16rem;
            padding-bottom: 0.12rem;
            img {
              float: left;
              background: #d8d8d8;
              width: 0.2rem;
              height: 0.2rem;
              // margin-left: 0.16rem;
              border-radius: 50%;
            }
            span {
              margin-left: 0.14rem;
              float: left;
              font-family: Mediums;
              font-size: 0.15rem;
              color: #202f1f;
              letter-spacing: -0.41px;
              line-height: 0.15rem;
            }
            em {
              float: right;
              text-align: right;
              font-family: Regular;
              font-size: 0.13rem;
              color: #adadad;
              letter-spacing: -0.36px;
              text-align: right;
            }
            p {
              clear: both;
              padding-top: 0.04rem;
              padding-left: 0.34rem;
              font-family: Regular;
              font-size: 0.13rem;
              color: #636363;
              letter-spacing: -0.36px;
              line-height: 0.13rem;
            }
          }
          .mission_info_center {
            padding-left: 0.42rem;
            margin: 0 0.08rem;
            padding-top: 0.12rem;
            padding-bottom: 0.12rem;
            p {
              float: left;
              font-family: Regular;
              font-size: 0.12rem;
              color: #001616;
              color: #818181;
              letter-spacing: -0.34px;
              line-height: 0.14rem;
            }
            img {
              float: right;
              height: 0.141rem;
              padding-right: 0.16rem;
              margin-bottom: 0.1rem;
            }
          }
        }
      }
      .task_item::before {
        content: "";
        display: block;
        height: 0.1rem;
        width: 100%;
      }
    }
  }
}
</style>
